package php.code;

import utils.Base;
import utils.titles.Title;
import php.code.instructions.VariableDeclaration;

/**
* Created by nuno-rafael-figueiredo on 23-05-2014.
*/
public class Variable extends Base {

    public Variable(String name) {
        super(Title.SNAKE_CASE, name);
    }

    public Variable(Title title) {
        super(Title.SNAKE_CASE, title);
    }

    @Override
    public String toString() {
        return "$" + super.toString();
    }

    public String getProperty(String key) {
        return toString() + "->" + (Character.isDigit(key.charAt(0)) ? "_" + key : key);
    }

    public VariableDeclaration declare(String value) {
        return new VariableDeclaration(this, value);
    }

    public String index(String key, String value) {
        return getName() + "[" + key + "] = " + value + ";";
    }
}
